home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / Utilities / Hardware / SCSItools / mtset.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-26  |  2.3 KB  |  90 lines

  1. /*
  2.  * mtset - set SCSI tape driver characteristics
  3.  *
  4.  * setmtd - set SCSI tape driver to a fixed block size
  5.  *      by John L. Chmielewski
  6.  *      Tue Feb 19, 1991
  7.  *
  8.  * Modified to take drive name argument and default to non-rewinding mode:
  9.  *      by David D. Johnson (ddj@gradient.com)
  10.  *      Sun Feb 24, 1991
  11.  *
  12.  * Modified to use switches to change tape device name and characteristics:
  13.  *      mtset [-d name] [-f size] [-i]
  14.  *      -d tape device name (default /dev/nrst0)
  15.  *      -f Sets the driver to fixed block mode, uses
  16.  *         argument of block size in bytes (default 512 bytes),
  17.  *         Variable block mode is default.
  18.  *      -i Inhibit illegal length (default is to allow illegal length)
  19.  */
  20.  
  21. /*
  22.                       USE AT YOUR OUR RISK. 
  23.       I NOT NOT BE RESPONSIBLE FOR PROBLEM CAUSED BY THIS PROGRAM.
  24.  */
  25.  
  26. #include <fcntl.h>
  27. #include <stdio.h>
  28. #include <sys/types.h>
  29. #include <nextdev/scsireg.h>
  30.  
  31. #define RSTDEVICE       "/dev/nrst0"
  32. #define BLOCKSIZE       512
  33. main(int argc, char *argv[])
  34. {
  35.     extern int optind;
  36.     extern char *optarg;
  37.         int fd;
  38.     int defsize = BLOCKSIZE;
  39.     int size = BLOCKSIZE;
  40.         char *deffile = RSTDEVICE;
  41.     char *file = RSTDEVICE;
  42.     u_int mode = MTIOCVARBLK;
  43.     u_int inhibit = MTIOCALILL;
  44.     char c;
  45.  
  46.     while ((c = getopt(argc, argv, "d:f:i")) != EOF) {
  47.         switch (c) {
  48.         case 'd':
  49.             file = optarg;
  50.             break;
  51.         case 'f':
  52.             mode = MTIOCFIXBLK;
  53.             size = atoi(optarg);
  54.             break;
  55.         case 'i':
  56.             inhibit = MTIOCINILL;
  57.             break;
  58.         default:
  59.                     fprintf(stderr,
  60.                             "usage: %s [-d device] [-f block-size] [-i]\n",
  61.                             argv[0]);
  62.             fprintf(stderr,
  63.                 "     -d tape device name (default %s)\n",
  64.                 deffile);
  65.             fprintf(stderr,
  66.                 "     -f set fix block mode with size (default size %d)\n",
  67.                 defsize);
  68.             fprintf(stderr,
  69.                 "     -i Inhibit illegal length\n");
  70.             fprintf(stderr,
  71.                 "     default: variable block mode, allow illegal length\n");
  72.                     exit(1);
  73.         }
  74.     }
  75.  
  76.         if ((fd = open(file, O_RDWR)) < 0) {
  77.                 perror(file);
  78.                 exit(1);
  79.         }
  80.         if (ioctl(fd, mode, &size) < 0) {
  81.                 perror("ioctl");
  82.                 exit(1);
  83.         }
  84.         if (ioctl(fd, inhibit) < 0) {
  85.                 perror("ioctl");
  86.                 exit(1);
  87.         }
  88.         (void) close(fd);
  89.         return 0;
  90. }